package ua.com.stormlabs.tiny.licenseserver.service;

import ua.com.stormlabs.tiny.licenseserver.beans.License;
import ua.com.stormlabs.tiny.licenseserver.beans.User;
import ua.com.stormlabs.tiny.licenseserver.storage.entities.LicenseEntity;
import ua.com.stormlabs.tiny.licenseserver.storage.entities.UserEntity;

/**
 * @author Denis Bondarenko
 * @version 03.12.11
 */
public final class BeanConverter {

    private BeanConverter() {
    }

    public static License convert(LicenseEntity licenseEntity) {
        return new License(licenseEntity.getLicenseName(), licenseEntity.getId());
    }

    public static User convert(UserEntity userEntity) {
        User user = new User();

        user.setLicenseType(userEntity.getLicense().getId());
        user.setLicenseName(userEntity.getLicense().getLicenseName());
        user.setCreateDate(userEntity.getCreateDate());
        user.setExpireDate(userEntity.getExpireDate());
        user.setId(userEntity.getId());
        user.setLicenseCode(userEntity.getLicenseCode());
        user.setMac(userEntity.getMac());
        user.setMacChecking(userEntity.isMacChecking());
        user.setUserName(userEntity.getUserName());

        return user;
    }

    public static UserEntity convert(User user, LicenseEntity licenseEntity) {
        UserEntity userEntity = new UserEntity();

        userEntity.setCreateDate(user.getCreateDate());
        userEntity.setExpireDate(user.getExpireDate());
        userEntity.setLicense(licenseEntity);
        userEntity.setLicenseCode(user.getLicenseCode());
        userEntity.setMac(user.getMac());
        userEntity.setMacChecking(user.getMacChecking());
        userEntity.setUserName(user.getUserName());

        return userEntity;
    }
}
